<template>
  <div class="tablets-page">
    <div class="page-header">
      <h1>华为平板</h1>
      <p>华为MatePad系列，生产力与娱乐的完美结合</p>
    </div>

    <el-row :gutter="20">
      <el-col :span="6" v-for="tablet in tablets" :key="tablet.id">
        <el-card class="tablet-card" shadow="hover" @click="viewDetail(tablet.id)">
          <div class="product-image-container">
            <img :src="tablet.image" :alt="tablet.name" class="product-image">
            <div class="product-badge" v-if="tablet.isNew">新品</div>
            <div class="product-badge discount" v-if="tablet.discount">热销</div>
          </div>
          <div class="product-info">
            <h3>{{ tablet.name }}</h3>
            <p class="product-desc">{{ tablet.description }}</p>
            <div class="product-price">
              <span class="current-price">¥{{ tablet.price }}</span>
              <span class="original-price" v-if="tablet.originalPrice">¥{{ tablet.originalPrice }}</span>
            </div>
            <div class="product-features">
              <span class="feature-tag" v-for="feature in tablet.features" :key="feature">{{ feature }}</span>
            </div>
            <div class="product-actions">
              <el-button type="primary" size="small" @click="viewDetail(tablet.id)">查看详情</el-button>
              <el-button type="success" size="small" @click="addToCart(tablet)">加入购物车</el-button>
            </div>
          </div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'
import { useCartStore } from '@/stores/cart'

const router = useRouter()
const cartStore = useCartStore()

const tablets = ref([
  {
    id: 'matepad-pro',
    name: 'HUAWEI MatePad Pro',
    price: '3999',
    originalPrice: '4499',
    description: '旗舰生产力平板，OLED全面屏',
    image: 'https://via.placeholder.com/300x300/45B7D1/FFFFFF?text=MatePad+Pro',
    features: ['OLED全面屏', 'M-Pencil', '多设备协同'],
    isNew: true,
    discount: true
  },
  {
    id: 'matepad-11',
    name: 'HUAWEI MatePad 11',
    price: '2999',
    description: '高性能学习平板，120Hz高刷',
    image: 'https://via.placeholder.com/300x300/96CEB4/FFFFFF?text=MatePad+11',
    features: ['120Hz高刷', '四扬声器', '学习模式'],
    isNew: false,
    discount: false
  },
  {
    id: 'matepad-paper',
    name: 'HUAWEI MatePad Paper',
    price: '2999',
    description: '墨水平板，护眼阅读体验',
    image: 'https://via.placeholder.com/300x300/333333/FFFFFF?text=MatePad+Paper',
    features: ['墨水屏', '护眼阅读', '手写笔记'],
    isNew: true,
    discount: true
  },
  {
    id: 'matepad-se',
    name: 'HUAWEI MatePad SE',
    price: '1299',
    originalPrice: '1499',
    description: '入门级平板，性价比之选',
    image: 'https://via.placeholder.com/300x300/999999/FFFFFF?text=MatePad+SE',
    features: ['10.4英寸', '护眼模式', '儿童模式'],
    isNew: false,
    discount: true
  },
  // 新增四个平板
  {
    id: 'matepad-10',
    name: 'HUAWEI MatePad 10.4',
    price: '1899',
    originalPrice: '2199',
    description: '教育平板，智慧学习',
    image: 'https://via.placeholder.com/300x300/5AC8FA/FFFFFF?text=MatePad+10.4',
    features: ['教育中心', '护眼认证', '长续航'],
    isNew: false,
    discount: true
  },
  {
    id: 'matepad-t10',
    name: 'HUAWEI MatePad T10',
    price: '1099',
    description: '儿童平板，安全可靠',
    image: 'https://via.placeholder.com/300x300/FF2D55/FFFFFF?text=MatePad+T10',
    features: ['儿童模式', '家长控制', '耐用设计'],
    isNew: true,
    discount: false
  },
  {
    id: 'matepad-c5',
    name: 'HUAWEI MatePad C5',
    price: '2199',
    description: '企业级平板，安全办公',
    image: 'https://via.placeholder.com/300x300/4CD964/FFFFFF?text=MatePad+C5',
    features: ['企业安全', '多任务', '远程管理'],
    isNew: false,
    discount: true
  },
  {
    id: 'matepad-air',
    name: 'HUAWEI MatePad Air',
    price: '2699',
    originalPrice: '2999',
    description: '轻薄平板，便携设计',
    image: 'https://via.placeholder.com/300x300/FF9500/FFFFFF?text=MatePad+Air',
    features: ['超轻薄', '全面屏', '快充'],
    isNew: true,
    discount: false
  }
])

const viewDetail = (tabletId) => {
  router.push(`/goods/${tabletId}`)
}

const addToCart = (tablet) => {
  cartStore.addToCart({
    id: tablet.id,
    name: tablet.name,
    price: tablet.price,
    image: tablet.image,
    description: tablet.description
  }, 1)
  ElMessage.success(`已添加 ${tablet.name} 到购物车`)
}
</script>

<style scoped>
.tablets-page {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
}

.page-header {
  text-align: center;
  margin-bottom: 40px;
  padding: 20px 0;
}

.page-header h1 {
  color: #c7000a;
  font-size: 32px;
  margin-bottom: 10px;
}

.page-header p {
  color: #666;
  font-size: 16px;
}

.tablet-card {
  margin-bottom: 20px;
  transition: all 0.3s;
  cursor: pointer;
}

.tablet-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
}

.product-image-container {
  position: relative;
}

.product-image {
  width: 100%;
  height: 200px;
  object-fit: cover;
}

.product-badge {
  position: absolute;
  top: 10px;
  right: 10px;
  background: #ff4757;
  color: white;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: bold;
}

.product-badge.discount {
  background: #ffa502;
  top: 40px;
}

.product-info {
  padding: 15px;
}

.product-info h3 {
  margin: 0 0 10px;
  color: #333;
  font-size: 18px;
  height: 24px;
  overflow: hidden;
}

.product-desc {
  color: #666;
  margin-bottom: 10px;
  font-size: 14px;
  height: 40px;
  overflow: hidden;
  line-height: 1.4;
}

.product-price {
  margin: 10px 0;
}

.current-price {
  color: #c7000a;
  font-size: 20px;
  font-weight: bold;
}

.original-price {
  color: #999;
  text-decoration: line-through;
  margin-left: 8px;
  font-size: 14px;
}

.product-features {
  margin: 10px 0;
}

.feature-tag {
  display: inline-block;
  background: #e3f2fd;
  color: #1976d2;
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 12px;
  margin-right: 5px;
  margin-bottom: 5px;
}

.product-actions {
  display: flex;
  gap: 8px;
  margin-top: 15px;
}

.product-actions .el-button {
  flex: 1;
}
</style>